#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int charcount[300];

int main()
{
    memset(charcount, 0, sizeof(charcount));
    string str;
    cin >> str;

    for(size_t i = 0; i < str.size(); i++)
    {
        charcount[str[i]] += 1;
    }

    priority_queue<int, vector<int>, greater<int>> small_heap;
    for(int i = 0; i < 300; i++)
    {
        if(charcount[i] == 0) continue;
        small_heap.push(charcount[i]);
    }
    // cout << small_heap.size() << endl;
    if(small_heap.size() == 1) 
    {
        cout << 1;
        return 0;
    }
    int ret = 0;
    while(small_heap.size() > 1)
    {
        int minimum = small_heap.top();
        small_heap.pop();
        int next_minimum = small_heap.top();
        small_heap.pop();
        int sum = minimum + next_minimum;
        small_heap.push(sum);
        ret += minimum + next_minimum;
    }
    cout << ret;
    return 0;
}